package com.itheima.set;

import java.util.TreeSet;

public class TreeSetDemo03 {
    public static void main(String[] args) {
        TreeSet<Integer> its = new TreeSet<>();
        its.add(5);
        its.add(1);
        its.add(1);
        its.add(3);
        System.out.println(its);//[1, 3, 5]

        TreeSet<Shape> shapes = new TreeSet<>();
        shapes.add(new Shape(10));
        shapes.add(new Shape(9));
        shapes.add(new Shape(11));
        System.out.println(shapes);//ClassCastException

    }
}
class Shape implements Comparable<Shape>{
    private Integer area;

    public Shape() {
    }

    public Shape(Integer area) {
        this.area = area;
    }

    public Integer getArea() {
        return area;
    }

    public void setArea(Integer area) {
        this.area = area;
    }

    @Override
    public String toString() {
        return "Shape{" +
                "area=" + area +
                '}';
    }

    @Override
    public int compareTo(Shape o) {
        return this.area - o.area;
    }
}
